#include <my_header.h>
// 读端
/* Usage: ./4_read_select */
int main(int argc, char *argv[]){                                  
    int fd_read = open("shared.pipe", O_RDONLY);
    ERROR_CHECK(fd_read, -1, "open read");

    char buf[1024] = {0};
    // 存储文件描述符的结构体
    fd_set set;

    while(1)
    {
        FD_ZERO(&set);  // 初始化
        FD_SET(fd_read, &set);  // 将文件描述符添加到set
        int res_select = select(fd_read+1, &set, NULL,
                                NULL, NULL);
        ERROR_CHECK(res_select, -1, "select");

        read(fd_read, buf, sizeof(buf));
        printf("read \n");
        sleep(2);   // 下一次读取停止2s
    }

    close(fd_read);
    return 0;
}


